/*
File: rgb_read.h
Read a pixmap from file in RGB format.
*/

#ifndef RGB_READ_H
#define RGB_READ_H

#include <stdio.h>
#include <stdlib.h>
#include "pixmap.h"

class RGBreader : public PixmapReader
{
  private:
  
  /* Information contained in header */
  unsigned short magic;
  unsigned short storage; /* type of encoding */
  unsigned short bpc;     /* number of bytes per pixel each channel */
  unsigned short x_size;  /* number of rows */
  unsigned short y_size;  /* number of columns */
  unsigned short z_size;  /* number of color channels (3 for RGB) */
  long min_pixel;         /* min pixel value */
  long max_pixel;         /* max pixel value */
  unsigned short dimensions;
  char dummy;
  char image_name[81];
  long color_map;

  /* Run-length tables (used if necessary) */
  unsigned long *starttab, *lengthtab;
  int tablen;

  /* File for reading */
  FILE * fd;

  public:

  /* constructor and descructor */
  RGBreader(void);
  ~RGBreader();

  /* functions from superclass */
  int okFilename(char * filename);
  int readPixmap(FILE * fd, class Pixmap * map);

  private:

  int readRGBheader(void);
  int readRGBimage(class Pixmap * map);

  void readtables(void);
  int rleoffset(int r, int c);
  int rlelength(int r, int c);
  int readscanline(Pixmap * map, int r, int c, int which_color);

}; // class

#endif
